package com.xiaobao.coalproperty.other.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.xiaobao.coalproperty.R;
import com.xiaobao.coalproperty.module.find.model.ForumDetailEntity;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.ViewHolder> {


    private Context mContext;
    private List<ForumDetailEntity.DataBean.CommentBean> mAdapterData;

    public CommentAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public List<ForumDetailEntity.DataBean.CommentBean> getAdapterData() {
        return mAdapterData;
    }

    public void setAdapterData(List<ForumDetailEntity.DataBean.CommentBean> mAdapterData) {
        this.mAdapterData = mAdapterData;
        this.notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_adapter_comment, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Glide.with(mContext).load(mAdapterData.get(position).getAvatar()).into(holder.ivHead);
        holder.tvName.setText(mAdapterData.get(position).getNickname());
        holder.tvContent.setText(mAdapterData.get(position).getContent());
        holder.tvTime.setText(mAdapterData.get(position).getDate());
    }

    @Override
    public int getItemCount() {
        if (mAdapterData == null) {
            return 0;
        }
        return mAdapterData.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        CircleImageView ivHead;
        TextView tvName, tvContent, tvTime;

        public ViewHolder(View itemView) {
            super(itemView);
            ivHead = itemView.findViewById(R.id.comment_head);
            tvName = itemView.findViewById(R.id.comment_name);
            tvContent = itemView.findViewById(R.id.comment_content);
            tvTime = itemView.findViewById(R.id.comment_time);
        }
    }

}
